package com.hntest.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.hntest.entity.LoginInfor;
import com.hntest.service.LoginInforService;
import com.hntest.util.MD5;

@Controller(value = "QiantaiController")
public class QianTaoController {

	@Autowired
	private LoginInforService loginService;
	
	// 前台注册
	@RequestMapping(value = "/doRegister", method = { RequestMethod.POST })
	public String dologin(LoginInfor u) {
		int n = loginService.doRegister(u);
		if(n>0) {
			return "redirect:/login.jsp";
		}
		return "redirect:/login.jsp?sp=no";
	}
	
	//前台登陆
		@RequestMapping(value="/doLogin",method= {RequestMethod.POST})
		public String dologin(@RequestParam String userName,@RequestParam String passWD,ModelMap modelMap) {
			LoginInfor u = new LoginInfor();
			u.setUserName(userName);
			u.setPassWD(MD5.encode(passWD));
			LoginInfor user = loginService.doLogin(u);
			if(user!=null) {
				modelMap.put("userlogin", user);
				return "forward:index.jsp";
			}
			return "redirect:login.jsp?sp=no";
		}
	
}
